/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>

*/
package cmd

import (
	"fmt"

	"gitee.com/lys_billy/bpf-map/pkg/bpf"
	"github.com/spf13/cobra"
)

// listCmd represents the list command
var listCmd = &cobra.Command{
	Use:   "list",
	Short: "bpf-map list --name=mapname ",
	Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
	Run: func(cmd *cobra.Command, args []string) {
		mapname, _ := cmd.Flags().GetString("name")
		m := bpf.ListMap(mapname)
		if m == nil {
			fmt.Errorf("map不存在")
		}
		for key, value := range m {
			fmt.Println(fmt.Sprintf("* %+v:%+v", key, value))
		}

	},
}

func init() {
	rootCmd.AddCommand(listCmd)

	// Here you will define your flags and configuration settings.
	listCmd.Flags().StringP("name", "n", "cilium-test-map", "--name=test")
}
